package com.significantfiles.snapshot.util;

import java.io.File;

import com.significantfiles.snapshot.engine.rt.x.IllegalConfigException;

public class FileUtil {

	
	public static File createDir(final File dir) throws IllegalConfigException {
		if (!dir.exists()) {
			final boolean mkdir = dir.mkdirs();

			if (mkdir)
				return dir;

			final String msg = "Couldn't create directory [dir: "
					+ dir.getAbsolutePath() + "].";
		
			throw new IllegalConfigException(msg);
		}

		if (dir.isDirectory())
			return dir;

		final String msg = "Path [path: "
				+ dir.getAbsolutePath()
				+ "] exists but doesn't refer a directory. ";
		
		throw new IllegalConfigException(msg);
	}
}
